package com.itheima.task;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/*
* 用反射去创建一个对象，有2种方式，尽量用代码去体现
* */
public class Demo2 {
    public static void main(String[] args) throws Exception {
        //第一种方式创建
        Class clazz = Class.forName("com.itheima.task.Student");
        Student student = (Student) clazz.newInstance();
        System.out.println(student);
        //第二种方式创建
        Class<Student> studentClass = Student.class;
        Constructor<Student> constructor = studentClass.getConstructor();
        Student student1 = constructor.newInstance();
        System.out.println(student1);
    }
}
